<template lang='pug'>
  .page
    .search-form
      Row(type="flex" justify="start")
        Col.pr-20.mb-15(:md="{ span: 12 }" :lg="{ span: 12 }" :xl="{ span: 8 }")
          span.label-txt.w80 顾问名称：
          Input(v-model="txtSearch"  placeholder="请输入顾问名称" clearable)
        Col.pr-20.mb-15(:md="{ span: 12 }" :lg="{ span: 12 }" :xl="{ span: 8 }")
          span.label-txt.w80 行业：
          Select(v-model="intIndustry" placeholder="请选择行业" clearable)
            Option(v-for="(item, index) in intIndustryArr" :value="item.e_type_id" :key="index") {{ item.e_name }}
        Col.pr-20.mb-15(:md="{ span: 12 }" :lg="{ span: 12 }" :xl="{ span: 8 }")
          span.label-txt.w80 职业：
          Select(v-model="intPosition"  placeholder="请选择职业" clearable)
            Option(v-for="(item, index) in intPositionArr" :value="item.e_type_id" :key="index") {{ item.e_name }}
        Col.pr-20.mb-15(:md="{ span: 12 }" :lg="{ span: 12 }" :xl="{ span: 8 }")
          span.label-txt.w80 学历：
          Select(v-model="intEducation"  placeholder="请选择学历" clearable)
            Option(v-for="(item, index) in eduList" :value="index" :key="index") {{ item }}
        Col.pr-20.mb-15(:md="{ span: 12 }" :lg="{ span: 12 }" :xl="{ span: 8 }")
          Button(type="info" @click="query") 查询
    .pl-20.pr-20.bg-white
      Table.hasTitle-table.beautiful-table(width="100%" stripe :loading="loading" :columns="thead" :data="listData")
        div(slot="header")
          .pull-left.table-title-lefttxt
            span.leftText
              | 招聘顾问:
              span.text-info.pl-5.pr-5.font-weight {{totalcount}}
              | 人
        template(slot-scope="{ row, index }" slot="havePositionNumber")
          span.u-d-info(@click="openHasJobModal") {{row.havePositionNumber}}
        .clearfix.pl-20.pr-20(slot="footer")
          Page(:total="totalcount" :current="pageIndex" :page-size="pageSize" prev-text="上一页" next-text="下一页" @on-change="pageChange" show-total)
    hasJobModal(ref="hasJobModal" :listData="hasJobData")
</template>

<script>
import fxzpApi from '@/api/fx-zp.api.js'
import hasJobModal from './modal/hasJob.vue'

export default {
  name: 'enterprise',
  data () {
    return {
      consultantId: '', // 顾问id
      // 搜索关键字
      txtSearch: '',
      intIndustry: null, // 行业
      intPosition: null, // 职位
      intEducation: null, // 学历
      // 翻页索引
      pageIndex: 1,
      // 每页的数目
      pageSize: 10,
      // 总条目
      totalcount: 0,
      listData: [],
      hasJobData: [], // 拥有职位数据
      loading: false,
      eduList: ['小学','初中','高中','中专','大专','本科','硕士（研究生）'],

      thead: [
        {
          title: '注册日期',
          align: 'center',
          width: 190,
          tooltip: true,
          render: (h, params) => {
            let row = params.row
            let date = ''
            if (row.data.consultant_adddata) {
              date = row.data.consultant_adddata.slice(0, 19).replace(/T/g,' ')
            }
            return h('span', date)
          }
        },
        {
          title: '姓名',
          align: 'center',
          width: 110,
          tooltip: true,
          render: (h, params) => {
            let row = params.row
            return h('span', row.data.consultant_name)
          }
        },
        {
          title: '年龄',
          align: 'center',
          width: 110,
          tooltip: true,
          render: (h, params) => {
            let row = params.row
            return h('span', row.data.consultant_age)
          }
        },
        {
          title: '学历',
          align: 'center',
          width: 110,
          tooltip: true,
          render: (h, params) => {
            let row = params.row
            return h('span', this.eduList[row.data.consultant_education])
          }
        },
        {
          title: '职业',
          align: 'center',
          width: 110,
          tooltip: true,
          render: (h, params) => {
            let row = params.row
            let str = ''
            let arr = this.getStatusFn('ConsultantPostion')
            let text = arr.filter((item) => {
              return item.id === row.data.consultant_position
            })
            if (text && text.length > 0) {
              str = text[0].e_name
            } else {
              str = '未填写'
            }
            return h('span', str)
          }
        },
        {
          title: '所在地',
          align: 'center',
          width: 110,
          tooltip: true,
          render: (h, params) => {
            let row = params.row
            return h('span', row.data.consultant_adress)
          }
        },
        {
          title: '所在行业',
          align: 'center',
          width: 110,
          tooltip: true,
          render: (h, params) => {
            let row = params.row
            let str = ''
            let arr = this.getStatusFn('CansultantWorkIndustry')
            let text = arr.filter((item) => {
              return item.id === row.data.consultant_workindustry
            })
            if (text && text.length > 0) {
              str = text[0].e_name
            } else {
              str = '未填写'
            }
            return h('span', str)
          }
        },
        {
          title: '最近登录时间',
          align: 'center',
          width: 190,
          tooltip: true,
          render: (h, params) => {
            let row = params.row
            let date = ''
            if (row.latelyLoginTime.createtime) {
              date = row.latelyLoginTime.createtime.slice(0, 19).replace(/T/g,' ')
            }
            return h('span', date)
          }
        },
        {
          title: '分享次数',
          align: 'center',
          width: 110,
          tooltip: true,
          key: 'shareNumber'
        },
        {
          title: '获得人才',
          align: 'center',
          width: 110,
          tooltip: true,
          key: 'acquiringTalentNumbaer'
        },
        {
          title: '投递推荐人才',
          align: 'center',
          width: 120,
          tooltip: true,
          key: 'deliveryNumber',
        },
        {
          title: '面试人才',
          align: 'center',
          width: 110,
          tooltip: true,
          key: 'interviewNumber',
        },
        {
          title: '入职人才',
          align: 'center',
          width: 110,
          tooltip: true,
          key: 'entryNumber'
        },
        {
          title: '过保人才',
          align: 'center',
          width: 110,
          tooltip: true,
          key: 'overProtectionNumbear'
        },
        {
          title: '获得奖金',
          align: 'center',
          width: 110,
          tooltip: true,
          key: 'bonus'
        },
        {
          title: '拥有职位',
          align: 'center',
          width: 110,
          tooltip: true,
          slot: 'havePositionNumber'
        },
        {
          title: '所属团队',
          align: 'center',
          width: 110,
          tooltip: true,
          key: 'affiliateTeam'
        },
        {
          title: '邀请码',
          align: 'center',
          width: 140,
          tooltip: true,
          render: (h, params) => {
            let row = params.row
            return h('span', row.data.consultant_invitationicode)
          }
        },
        {
          title: '拥有团队',
          align: 'center',
          width: 110,
          tooltip: true,
          key: 'haveTeamNumber',
        },
        {
          title: '目前等级',
          width: 110,
          tooltip: true,
          render: (h, params) => {
            let row = params.row
            return h('span', {
            }, row.levelData.consultant_levelname)
          }
        },
        {
          title: '目前积分',
          align: 'center',
          width: 110,
          tooltip: true,
          render: (h, params) => {
            let row = params.row
            return h('span', {
            }, row.data.consultant_integral)
          }
        },
        {
          title: '平台补贴',
          align: 'center',
          width: 110,
          tooltip: true,
          render: (h, params) => {
            let row = params.row
            return h('span', {
            }, row.levelData.platform_reward)
          }
        }
      ]
    }
  },
  components: {
    hasJobModal
  },
  mounted () {
    this.getListData()
  },
  computed: {
    intIndustryArr () {
      return this.getStatusFn('CansultantWorkIndustry')
    },
    intPositionArr () {
      return this.getStatusFn('ConsultantPostion')
    }
  },
  methods: {
    // 获取企业列表
    getListData () {
      this.loading = true
      fxzpApi.GetConsultants({
        txtSearch: this.txtSearch,
        intIndustry: this.intIndustry,
        intPosition: this.intPosition,
        intEducation: this.intEducation,
        PageSize  : this.pageSize,
        PageIndex : this.pageIndex
      }).then(res => {
        this.loading = false
        if (res.data.success) {
          this.listData = res.data.data
          this.totalcount = res.data.totalRows
        } else {
          this.listData = []
          this.totalcount = 0
        }
      })
    },
    // 查询
    query () {
      this.pageIndex = 1
      this.getListData()
    },
    // 获取拥有职位数据
    getHasJobData () {
      fxzpApi.GetConsultantPositions({
        ConsultantId: this.consultantId,
        Type: 2
      }).then(res => {
        console.log(res)
      })
    },
    // 查看顾问拥有的职位
    openHasJobModal () {
      this.getHasJobData()
      this.$refs.hasJobModal.openModal()
    },
    // 翻页
    pageChange (index) {
      this.pageIndex = index
      this.getListData()
    },
    getStatusFn (encode) {
      let allStatus = JSON.parse(localStorage.getItem('FXZP_STATUS'))
      // console.log(allStatus)
      let statusArr = allStatus.filter((item) => {
        return item.e_encode === encode
      })
      return statusArr 
    }
  }
  
}
</script>

<style lang="less">
</style>
